TOOL.Category   = "Carbon Systems"
TOOL.Name     = "#Storages"
TOOL.Command    = nil
TOOL.ConfigName   = ""
if (CLIENT and GetConVarNumber("CAF_UseTab") == 1) then TOOL.Tab = "Custom Addon Framework" end

TOOL.ClientConVar["type"] = "sol_lstore"
TOOL.ClientConVar["model"] = "models/crate_reactor.mdl"

cleanup.Register('carbonsystem')

if ( CLIENT ) then
	language.Add( "Tool_sol_storage_name", "Carbon Storages" )
	language.Add( "Tool_sol_storage_desc", "Spawns A Storage for use with Carbon Systems." )
	language.Add( "Tool_sol_storage_0", "Left Click: Spawn A Storage. Right Click: Repair A Storage" )

	language.Add( "Undone_sol_storage", "Carbon Storage Undone" )
	language.Add( "Cleanup_sol_storage", "Carbon Storage" )
	language.Add( "Cleaned_sol_storage", "Cleaned up all Carbon Storages" )
	language.Add( "SBoxLimit_sol_storage", "Maximum Carbon Storages Reached" )
end

if not CAF or not CAF.GetAddon("Resource Distribution") then Error("Please Install Resource Distribution Addon.'" ) return end
if not CAF or not CAF.GetAddon("Life Support") then return end

if( SERVER ) then
	CreateConVar("sbox_maxsol_storage", 24)

	function Makesol_storage( ply, ang, pos, stortype, model, frozen )
		if ( !ply:CheckLimit( "sol_storage" ) ) then return nil end

		--Create gas storage
		local ent = ents.Create( stortype )

		-- Set position and angle
		ent:SetPos( pos )
		ent:SetAngles( ang )

		ent:Spawn()
		ent:Activate()

		ent:SetVar("Owner", ply)
		ent:SetPlayer(ply)

		ent.Class = stortype

		if (frozen) then
			local phys = ent:GetPhysicsObject()
			if (phys:IsValid()) then
				phys:EnableMotion( false )
				ply:AddFrozenPhysicsObject( ent, phys )
			end
		end

		ply:AddCount("sol_storage", ent)

		return ent
	end

		duplicator.RegisterEntityClass("Large Carbon Tank", Makesol_storage, "Ang", "Pos", "Class", "model", "frozen")
		duplicator.RegisterEntityClass("Medium Carbon Tank", Makesol_storage, "Ang", "Pos", "Class", "model", "frozen")
		duplicator.RegisterEntityClass("Small Carbon Tank", Makesol_storage, "Ang", "Pos", "Class", "model", "frozen")

end

if (GAMEMODE.Name == "SpaceBuild" || SpaceBuild) then MsgAll("You need the new Spacebuild (3) to use carbon systems, you are using Spacebuild1!\n") end
if (GAMEMODE.Name == "SpaceBuild2" || SpaceBuild2) then MsgAll("You need the new Spacebuild(3) to use carbon systems, you are using Spacebuild2!\n") end
local sol_stor_models = {
		{ "#Large Carbon Tank", "models/crate_reactor.mdl", "sol_hstore" },
		{ "#Medium Carbon Tank", "models/crate_watersmall.mdl", "sol_lstore" },
		{ "#Small Carbon Tank", "models/crate_watersmall", "sol_sstore" },

}
CAF_ToolRegister( TOOL, sol_stor_models, Makesol_storage,"sol_storage",24)
